﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace LightGameLibs
{
    [System.Serializable]
    public class SerializableEvent : UnityEvent<EventArgs> { }
    [System.Serializable]
    public class String2StringDict : SerializableDictionary<string, string> { }
    [System.Serializable]
    public class DebugTag2SwitchDict : SerializableDictionary<DebugTag, bool> { }
    [System.Serializable]
    public class DBTag2TextDict : SerializableDictionary<DBTag, DBTextAsset> { }

    public static class TypeDefine
    {
        private static WaitForEndOfFrame s_endOfFrame;
        private static WaitForFixedUpdate s_fixedUpdate;
        private static Dictionary<float, WaitForSeconds> s_WFSDict;
        private static Dictionary<float, WaitForSecondsRealtime> s_WFSRDict;

        public static WaitForEndOfFrame EndOfFrame
        {
            get
            {
                if (null == s_endOfFrame)
                {
                    s_endOfFrame = new WaitForEndOfFrame();
                }
                return s_endOfFrame;
            }
        }

        public static WaitForFixedUpdate FixedUpdate
        {
            get
            {
                if (null == s_fixedUpdate)
                {
                    s_fixedUpdate = new WaitForFixedUpdate();
                }
                return s_fixedUpdate;
            }
        }

        public static WaitForSeconds GetWaitForSeconds(float sec)
        {
            if (null == s_WFSDict)
            {
                s_WFSDict = new Dictionary<float, WaitForSeconds>();
            }

            WaitForSeconds WFS = null;
            if (!s_WFSDict.TryGetValue(sec, out WFS))
            {
                var wfs = new WaitForSeconds(sec);
                s_WFSDict.Add(sec, wfs);
                return wfs;
            }

            return WFS;
        }

        public static WaitForSecondsRealtime GetWaitForSecondsRealTime(float sec)
        {
            if (null == s_WFSRDict)
            {
                s_WFSRDict = new Dictionary<float, WaitForSecondsRealtime>();
            }

            WaitForSecondsRealtime WFSR = null;
            if (!s_WFSRDict.TryGetValue(sec, out WFSR))
            {
                var wfsr = new WaitForSecondsRealtime(sec);
                s_WFSRDict.Add(sec, wfsr);
                return wfsr;
            }

            return WFSR;
        }
    }
}
